﻿Imports CapaLogica.CL.Tema

Public Class frmBuscarTema

    Private Sub tsbNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'frmRegistrarModificarTema.lblTituloRegistrarTema.Visible = True
        ''frmRegistrarModificarTema.lblTituloModificarTema.Visible = False
        ''frmRegistrarModificarTema.tsbNuevo.Visible = True

        'frmRegistrarModificarTema.ShowDialog()

    End Sub

    Private Sub tsbModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'frmRegistrarModificarTema.lblTituloRegistrarTema.Visible = False
        ''frmRegistrarModificarTema.lblTituloModificarTema.Visible = True
        ''frmRegistrarModificarTema.tsbNuevo.Visible = False

        'frmRegistrarModificarTema.ShowDialog()
    End Sub

    Private Sub tsbCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click

        Dim nombre As String
        nombre = txtTema.Text

        If txtForo.Text = Nothing And txtTema.Text = Nothing Then
            dtvTema.DataSource = GestorTema.buscarTodosTema()
        Else
            If txtForo.Text <> Nothing Then
                dtvTema.DataSource = GestorTema.buscarTema(txtForo.Text)
            Else
                If txtTema.Text <> Nothing Then
                    dtvTema.DataSource = GestorTema.buscarTemaPorNombre(nombre)
                End If

            End If
        End If
    End Sub

    Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If ((dtvTema.CurrentRow Is Nothing) OrElse (dtvTema.SelectedRows.Count = 0)) Then
            MsgBox("Debe de seleccionar un tema antes de eliminarlo", MsgBoxStyle.Exclamation, "Error")
            Exit Sub
        Else
            Dim mensaje As String
            mensaje = "Desea eliminar El tema"
            Dim button As DialogResult = MessageBox.Show(mensaje, "Usuario", MessageBoxButtons.YesNoCancel,
                                                        MessageBoxIcon.Warning)
            If button = DialogResult.Yes Then
                GestorTema.eliminarTema(CInt(dtvTema.SelectedRows(0).Cells(0).Value))
                MsgBox("El tema se ha eliminado con éxito")

            Else
                MsgBox("El tema no se ha eliminado")
            End If

        End If
    End Sub



    Private Sub actualizar()
        txtForo.Text = ""
        txtTema.Text = ""
        txtForo.Enabled = True
        txtTema.Enabled = True
        dtvTema.DataSource = Nothing

    End Sub

    Private Sub tsbLimpiarFiltro_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbLimpiarFiltro.Click
        actualizar()
    End Sub

    Private Sub txtForo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtForo.TextChanged
        If txtForo.Text.Length > 0 Then
            txtTema.Text = ""

            txtTema.Enabled = False
          
        Else
            txtTema.Enabled = True
          End If
    End Sub

    Private Sub txtTema_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTema.TextChanged
        If txtTema.Text.Length > 0 Then
            txtForo.Text = ""

            txtForo.Enabled = False
           
        Else
            txtForo.Enabled = True
           End If
    End Sub


    Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        If ((dtvTema.CurrentRow Is Nothing) OrElse (dtvTema.SelectedRows.Count = 0)) Then
            MsgBox("Debe de seleccionar un curso antes de modificar", MsgBoxStyle.Exclamation, "Error")
            Exit Sub
        Else
            Dim id As Int32 = CInt(dtvTema.SelectedRows(0).Cells(0).Value)
            Dim nombre As String = CStr(dtvTema.SelectedRows(0).Cells(1).Value)
            Dim descripcion As String = CStr(dtvTema.SelectedRows(0).Cells(2).Value)
            Dim idForo As Int32 = CInt(dtvTema.SelectedRows(0).Cells(3).Value)
            Dim fechaInicio As DateTime = (dtvTema.SelectedRows(0).Cells(4).Value)
            Dim fechaFin As DateTime = (dtvTema.SelectedRows(0).Cells(5).Value)
            Dim calificacion As Boolean = CBool(dtvTema.SelectedRows(0).Cells(6).Value)
            Dim justificacion As String = CStr(dtvTema.SelectedRows(0).Cells(8).Value)
            Dim cantAportes As Int32 = CInt(dtvTema.SelectedRows(0).Cells(7).Value)

            Dim frmModificar As New frmModificarTema(id, nombre, descripcion, idForo, fechaInicio, fechaFin, calificacion, justificacion, cantAportes)
            frmModificar.ShowDialog()

        End If
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Me.Dispose()
    End Sub
End Class
